package com.xiaoge.demo.web;


import com.xiaoge.demo.configs.annotation.token.PassToken;
import com.xiaoge.demo.configs.annotation.token.TokenService;
import com.xiaoge.demo.core.Result;
import com.xiaoge.demo.core.ResultGenerator;
import com.xiaoge.demo.dao.UserDao;
import com.xiaoge.demo.pojo.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "测试token")
@RestController
@RequestMapping("/token")
public class TokenController {

    @Autowired
    TokenService mTokenService;
    @Autowired
    UserDao mUserDao;

    @PostMapping("/query")
    @PassToken
    @ApiOperation(value = "生成token")
    public Result bannerInfoQuery() {
        User user = mUserDao.getOne("U00000000001");
        String token = mTokenService.getToken(user);
        return ResultGenerator.genSuccessResult(token);
    }

    @PostMapping("/detail")
    @ApiOperation(value = "校验token token必须放在head中")
    public Result detail(@RequestParam String token) {
        String data = "参数校验:" + token;
        return ResultGenerator.genSuccessResult(data);
    }
}